/**
 * 
 */
package com.sun.java.rmi.engine;

import java.rmi.AccessException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import com.sun.java.rmi.Compute;
import com.sun.java.rmi.Task;

/**
 * @author Jun
 *
 */
public class ComputeEngine implements Compute {
	
	public ComputeEngine(){
		super();
	}

	/* (non-Javadoc)
	 * @see com.sun.java.rmi.Compute#executeTask(com.sun.java.rmi.Task)
	 */
	public <T> T executeTask(Task<T> t) throws RemoteException {
		// TODO Auto-generated method stub
		return t.execute();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		if(System.getSecurityManager() == null){
			System.setSecurityManager(new SecurityManager());
		}
		try {
			String name = "Compute";
			Compute engine = new ComputeEngine();
			Compute stub = (Compute)UnicastRemoteObject.exportObject(engine,0);
			Registry registry = LocateRegistry.getRegistry();
			registry.rebind(name, stub);;
			System.out.println("ComputeEngine bound");
		} catch (AccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
